﻿using Liuliu.ScriptEngine;
using Newtonsoft.Json;
using System.Data;
using System.Diagnostics;
using System.Reflection;

namespace GmPrizedrawTool
{
    /// <summary>
    /// 随机奖励
    /// </summary>
    internal class RandomReward
    {
        public static DateTime RewardTime = DateTime.Now.AddMinutes(0);//下次抽奖[幸运财神]时间
        public static int RewardTimeSpan = 0;//下次[幸运财神]刷新间隔
        public static DateTime RandromTime = DateTime.Now.AddMinutes(5);//下次随机BOSS[游荡英灵]刷新时间
        public static string RandromXY = "";//下次游荡英灵刷新坐标位置
        public static string RandromMap = "";//下次游荡英灵刷新坐标所在地图
        public static int RandromTimeSpan = 0;//下次游荡英灵刷新间隔
        public static bool RandromRefrshYG = false;//随机刷新预告
        public static bool RewardRefrshYG = false;//抽奖刷新预告
        public static string NextRandromRefrshYGNotice = "";//下次随机boss刷新预告喊话内容
        public static string NextRewardRefrshYGNotice = "";//下次抽奖boss刷新预告喊话内容
        public static List<BossEntityModel> BossList = new List<BossEntityModel>();//Boss列表
        public static List<DisableMap> MapList = new List<DisableMap>();//区域坐标限制列表
        public static List<GameMapInfo> allMapList = new List<GameMapInfo>();//所有地图
        public static List<YouDangBoss> YouDangPointList = new List<YouDangBoss>();//游荡英灵刷新坐标

        /// <summary>
        /// 开始抽奖
        /// </summary>
        public static void StartReward(int Hwnd)
        {
            DmPlugin dm = Program.dm;
            LoadBossInfoList();//加载BOSS信息
            GetDisableMap();//禁止刷怪地图
            LoadMapInfo();//加载所有地图列表
            LoadYouDangPointInfo();
            InitRewardAndRandromInfo();//初始化抽奖信息
            bool disConnection = false;
            int runTimeLenth = 0;//运行时长
            int runTimeCount = 0;//计数器
            while (true)
            {
                //判断是否登录页面报错
                DateTime nowTime = DateTime.Now;
                int aX=0,aY=0;
                int dm_ret = dm.FindPic(451, 415, 586, 456, "Config\\loginerr.bmp", "000000", 0.8, 0, out aX, out aY);
                if (dm_ret != -1)
                {
                    Console.WriteLine("检测到断开连接掉线，准备重连...");
                    dm.MoveToClick(495, 443);
                    Thread.Sleep(100);
                    disConnection = true;
                    break;
                }
                //判断是否被击杀掉
                dm_ret = dm.FindPic(496, 435, 522, 450, "Config\\killed.bmp", "000000", 0.8, 0, out aX, out aY);
                if (dm_ret != -1)
                {
                    Console.WriteLine("检测到被击杀死亡...");
                    dm.MoveToClick(513, 444);
                    Thread.Sleep(50);
                    continue;
                }
                try
                {
                    if (RewardTime <= nowTime)//玩家抽奖
                    {
                        //随机获取要抽奖的目标财神，根据财神匹配对应等级的玩家，已达到控制目标财神刷新概率
                        BossEntityModel NpcInfo = GetRandomNpc(1, 0);
                        if (NpcInfo == null) {
                            continue;
                        }
                        Console.WriteLine($"抽取到的财神：{NpcInfo.Name}");
                        UserInfoModel userInfo = GetRandomOnlineUser(NpcInfo.chrLevL, NpcInfo.chrLevH);
                        if (userInfo == null)
                        {
                            RewardTime = nowTime.AddMilliseconds(20);
                            Console.WriteLine($"----{NpcInfo.Name}未匹配到合适的玩家，即将重新抽奖...");
                            continue;
                        }
                        else {
                            //判断玩家等级是否在财神等级之间，如果是则表示系统抽奖，如果不是则为指定人抽奖，重新取财神
                            if (userInfo.Level < NpcInfo.chrLevL || userInfo.Level > NpcInfo.chrLevH) {
                                NpcInfo = GetRandomNpc(1, userInfo.Level);
                                Console.WriteLine($"指定玩家获取,重新抽取对应等级财神：{NpcInfo.Name}");
                            }
                        }
                        Console.WriteLine($"中奖玩家：{userInfo.CharName}，等级：{userInfo.Level}");
                        string UserName = userInfo.CharName;
                        //获取坐标
                        Process p = Program.golobalProcess;
                        var baseAddress = p.MainModule.BaseAddress + 0x00AB97BC;
                        Thread.Sleep(300);
                        int x = dm.ReadInt(Hwnd, $"[[[{baseAddress.ToString("X")}]+0]+8]+10c", 0);
                        int y = dm.ReadInt(Hwnd, $"[[[{baseAddress.ToString("X")}]+0]+8]+110", 0);
                        int newX =0,newY =0;
                        //发送指令，移动到玩家身边
                        dm.SendString(Hwnd, $"-follow {UserName}");
                        Thread.Sleep(300);
                        dm.KeyPress(13);
                        Thread.Sleep(300);
                        ListenPosationChange(dm, Hwnd, x, y, out newX, out newY);
                        if (newX == 0 && newY == 0) 
                        {
                            continue;
                        }
                        #region 通过坐标区域判断是否在安全区，安全区不刷奖励重新获取用户
                        #region //初步通过是否能PK图标判断,暂时屏蔽（会过滤掉幻境中的玩家）
                        //int intX = 0, intY = 0;
                        //int dm_ret = dm.FindPic(182, 26, 200, 44, "Config\\pk.bmp", "000000", 0.8, 0, out intX, out intY);
                        //for (int i = 0; i < 3; i++)
                        //{
                        //    //多判断两次，确保确定不在安全区内
                        //    if (dm_ret != -1)
                        //    {
                        //        break;
                        //    }
                        //    dm_ret = dm.FindPic(182, 26, 200, 44, "Config\\pk.bmp", "000000", 0.8, 0, out intX, out intY);
                        //    Thread.Sleep(200);
                        //}
                        //if (dm_ret != -1)
                        //{
                        //    Console.WriteLine($"玩家{userInfo.CharName},坐标[{newX},{newY}],在安全区");
                        //    //GM管理员回到初始位置
                        //    //dm.SendString(Hwnd, $"-moveto 90 150");
                        //    //Thread.Sleep(300);
                        //    //dm.KeyPress(13);
                        //    //Thread.Sleep(300);
                        //    RewardTime = nowTime.AddMilliseconds(20);
                        //    continue;
                        //} 
                        #endregion
                        //通过坐标验证是否处于合法刷怪位置
                        if (!IsRightfulPosation(newX, newY))
                        {
                            Console.WriteLine($"玩家{userInfo.CharName},坐标[{newX},{newY}],在安全区,即将重新抽奖,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
                            RewardTime = nowTime.AddMilliseconds(20);
                            continue;
                        }
                        #endregion 判断是否在安全区，安全区不刷奖励重新获取用户

                        //直接创建NPC
                        dm.SendString(Hwnd, $"-createnpc {NpcInfo.ID} {NpcInfo.Name}");
                        Thread.Sleep(200);
                        dm.KeyPress(13);

                        Thread.Sleep(2000);

                        //GM管理员回到初始位置
                        dm.SendString(Hwnd, $"-moveto 90 150");
                        Thread.Sleep(300);
                        dm.KeyPress(13);
                        Thread.Sleep(300);

                        string NoticeContent = "";
                        if (Program.NoticePointLevel > 0 && NpcInfo.chrLevH < Program.NoticePointLevel)//限制报告等级
                        {
                            NoticeContent = NpcInfo.RefreshNotice.Replace("{wanjia}", $"[{UserName}]").Replace("{zuobiao}", $"你身边");
                        }
                        else {
                            NoticeContent = NpcInfo.RefreshNotice.Replace("{wanjia}", $"[{UserName}]").Replace("{zuobiao}", $"[{newX}, {newY}]");
                        }
                        Console.WriteLine($"{NoticeContent}【{DateTime.Now.ToString("MM-dd HH:mm:ss")}】");
                        SendOneNotice($"{NoticeContent}");

                        GetNextRewardTime(1);//设置下次抽奖时间
                        SendBossKilledInfo(NpcInfo.ID, RewardTimeSpan);//调用API上传下次Boss刷新信息
                        RewardRefrshYG = false;//重置为未预告
                        NextRewardRefrshYGNotice = NpcInfo.YuGaoNotice;
                    }
                    if (RandromTime <= nowTime)//随机BOSS游荡英灵
                    {
                        BossEntityModel NpcInfo = GetRandomNpc(0, 0);
                        if (NpcInfo == null)
                        {
                            continue;
                        }
                        string refreshPosition = "";
                        if (string.IsNullOrEmpty(RandromXY))
                        {
                            //获取可能出现的所有坐标随机取一个
                            Random Random = new Random();
                            int RandomVal = Random.Next(0, YouDangPointList.Count);
                            YouDangBoss ydBoss = YouDangPointList[RandomVal];
                            refreshPosition = ydBoss.Point.Replace("\"", "");
                        }
                        else
                        {
                            refreshPosition = RandromXY;
                        }
                        //获取坐标
                        Process p = Program.golobalProcess;
                        var baseAddress = p.MainModule.BaseAddress + 0x00AB97BC;
                        Thread.Sleep(300);
                        int x = dm.ReadInt(Hwnd, $"[[[{baseAddress.ToString("X")}]+0]+8]+10c", 0);
                        int y = dm.ReadInt(Hwnd, $"[[[{baseAddress.ToString("X")}]+0]+8]+110", 0);
                        int newX = 0, newY = 0;
                        string NoticeContent = NpcInfo.RefreshNotice.Replace("{zuobiao}", $"[{refreshPosition.Replace(",", ", ")}]");
                        Console.WriteLine($"{NoticeContent}【{DateTime.Now.ToString("MM-dd HH:mm:ss")}】");
                        SendOneNotice($"{NoticeContent}");
                        //发送指令，移动到指定坐标
                        dm.SendString(Hwnd, $"-moveto {refreshPosition.Replace(',', ' ')}");
                        Thread.Sleep(300);
                        dm.KeyPress(13);
                        Thread.Sleep(300);
                        ListenPosationChange(dm, Hwnd, x, y, out newX, out newY);
                        if (newX == 0 && newY == 0)
                        {
                            continue;
                        }
                        //直接创建NPC
                        dm.SendString(Hwnd, $"-createnpc {NpcInfo.ID} {NpcInfo.Name}");
                        Thread.Sleep(300);
                        dm.KeyPress(13);
                        Thread.Sleep(300);

                        Thread.Sleep(2000);

                        //GM管理员回到初始位置
                        dm.SendString(Hwnd, $"-moveto 90 150");
                        Thread.Sleep(300);
                        dm.KeyPress(13);
                        Thread.Sleep(300);

                        GetNextRewardTime(0);//设置下次随机Boss刷新
                        SendBossKilledInfo(3888, RandromTimeSpan, RandromMap);//调用API上传下次Boss刷新信息
                        RandromRefrshYG = false;//重置为未预告
                        NextRandromRefrshYGNotice = NpcInfo.YuGaoNotice;
                    }
                    //预告刷新公告
                    //判断条件：还未预告过，距离刷新时间不足6分钟且超过5分钟时提示
                    if ((RewardTime - nowTime).TotalMinutes > 5 && (RewardTime - nowTime).TotalMinutes < 6 && !RewardRefrshYG)
                    {
                        if (!string.IsNullOrEmpty(NextRewardRefrshYGNotice))
                        {
                            if (SendOneNotice($"{NextRewardRefrshYGNotice}"))
                            {
                                Console.WriteLine($"{NextRewardRefrshYGNotice},【{DateTime.Now.ToString("MM-dd HH:mm:ss")}】");
                                RewardRefrshYG = true;
                            }
                        }
                    }
                    if ((RandromTime - nowTime).TotalMinutes > 5 && (RandromTime - nowTime).TotalMinutes < 6 && !RandromRefrshYG)
                    {
                        if (!string.IsNullOrEmpty(NextRandromRefrshYGNotice))
                        {
                            if (SendOneNotice($"{NextRandromRefrshYGNotice}"))
                            {
                                Console.WriteLine($"{NextRandromRefrshYGNotice},坐标：{RandromMap}-{RandromXY},【{DateTime.Now.ToString("MM-dd HH:mm:ss")}】");
                                RandromRefrshYG = true;
                            }
                        }
                    }

                    //移动位置
                    if (runTimeCount % 2 == 0)
                    {
                        dm.MoveToClick(500, 390);
                    }
                    else
                    {
                        dm.MoveToClick(360, 370);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"发现异常: {ex.Message}");
                }
                runTimeLenth += 10;
                runTimeCount += 1;
                Thread.Sleep(5000);//每5s检查一次
            }
            //检测到掉线断开连接，重连
            if (disConnection) {
                LoginGame.StartLogin(Hwnd, 2);
            }
        }

        /// <summary>
        /// 初始化抽奖信息
        /// </summary>
        public static void InitRewardAndRandromInfo()
        {
            //幸运财神
            RewardTime = DateTime.Now.AddMinutes(new Random().Next(10, 20));//1035
            //游荡英灵
            int refreshMinute = new Random().Next(0, 5);
            RandromTime = DateTime.Now.AddMinutes(refreshMinute);
            //游荡英灵下次刷新坐标随机取一个
            Random Random = new Random();
            int RandomVal = Random.Next(0, YouDangPointList.Count);
            YouDangBoss ydBoss = YouDangPointList[RandomVal];
            RandromXY = ydBoss.Point.Replace("\"", "");
            RandromMap = ydBoss.MapName;
            //获取地图名称
            RandromTimeSpan = refreshMinute * 60;
        }

        /// <summary>
        /// 设置下次抽奖时间
        /// </summary>
        /// <param name="Type">0:随机,1:玩家抽奖</param>
        public static void GetNextRewardTime(int Type)
        {
            string Interval = Type == 0 ? Program.RandromInterval : Program.RewardInterval;
            string[] IntervalArr = Interval.ToString().Split(',');
            Random Random = new Random();
            int RandomVal = Random.Next(0, IntervalArr.Length);
            int Minute = Convert.ToInt32(IntervalArr[RandomVal]);
            if (Type == 0)
            {
                RandromTime = DateTime.Now.AddMinutes(Minute);
                Random Random2 = new Random();
                int RandomVal2 = Random.Next(0, YouDangPointList.Count);
                YouDangBoss ydBoss = YouDangPointList[RandomVal2];
                RandromXY = ydBoss.Point.Replace("\"", "");
                RandromMap = ydBoss.MapName;
                RandromTimeSpan = Minute * 60;
            }
            else {
                RewardTime = DateTime.Now.AddMinutes(Minute);
                RewardTimeSpan = Minute * 60;
            }
        }

        /// <summary>
        /// 通过地图名随机返回一个当前地图中的坐标位置
        /// </summary>
        /// <param name="mapName"></param>
        /// <returns></returns>
        public static string GetRandPosation(string mapName)
        {
            List<GameMapInfo> mapInfos = allMapList.FindAll(p=>p.MapName.Contains(mapName));
            Random random = new Random();
            if (mapInfos != null && mapInfos.Count > 0) { 
                int randIndex = random.Next(0, mapInfos.Count);
                GameMapInfo mapInfo = mapInfos[randIndex];
                int X = 0, Y = 0;
                X = random.Next(mapInfo.LeftX, mapInfo.LeftX + mapInfo.MapLenth);
                Y = random.Next(mapInfo.LeftY - mapInfo.MapLenth, mapInfo.LeftY);
                //判断该坐标是否在可刷新boss区域
                while (!IsRightfulPosation(X, Y, mapInfo.MapLenth))
                {
                    X = random.Next(mapInfo.LeftX, mapInfo.LeftX + mapInfo.MapLenth);
                    Y = random.Next(mapInfo.LeftY - mapInfo.MapLenth, mapInfo.LeftY);
                }
                return $"{X},{Y}";
            }
            return "";
        }

        /// <summary>
        /// 加载Boss信息
        /// </summary>
        public static void LoadBossInfoList()
        {
            KillBoss.LoadBossInfo();
            if (KillBoss.BossCsvDt != null && KillBoss.BossCsvDt.Rows.Count > 0)
            {
                for (int i = 1; i < KillBoss.BossCsvDt.Rows.Count; i++)
                {
                    BossEntityModel model = new BossEntityModel();
                    DataRow row = KillBoss.BossCsvDt.Rows[i];
                    if (row["COL7"].ToString() != "xitong")
                    {
                        model.ID = Convert.ToInt32(row["COL0"]);
                        model.Name = row["COL1"].ToString();
                        model.Avator = row["COL2"].ToString();
                        model.Point = row["COL3"].ToString();
                        model.TimeSpan = Convert.ToInt32(row["COL4"]);
                        model.StartTime = row["COL5"].ToString();
                        model.EndTime = row["COL6"].ToString();
                        model.RefreshType = row["COL7"].ToString();
                        model.RefreshNotice = row["COL8"].ToString();
                        model.YuGaoNotice = row["COL9"].ToString();
                        string LevelStr = row["COL10"].ToString();
                        if (LevelStr.Contains("-"))
                        {
                            string[] levelArr = LevelStr.Split('-');
                            model.chrLevL = Convert.ToInt32(levelArr[0]);
                            model.chrLevH = Convert.ToInt32(levelArr[1]);
                        }
                        model.mapName = row["COL11"].ToString();
                        model.refreshGL = Convert.ToInt32(row["COL12"]);
                        BossList.Add(model);
                    }
                }
            }
        }

        /// <summary>
        /// 监听GM账号移动后坐标是否变化
        /// </summary>
        /// <param name="dm">大漠对象</param>
        /// <param name="Hwnd">句柄</param>
        /// <param name="oldX">初始X坐标</param>
        /// <param name="oldY">初始Y坐标</param>
        /// <param name="newX">移动后X坐标</param>
        /// <param name="newY">移动后Y坐标</param>
        public static void ListenPosationChange(DmPlugin dm, int Hwnd, int oldX, int oldY, out int newX, out int newY)
        {
            int nowX = oldX, nowY = oldY;
            while (true)
            {
                if (oldX != nowX && oldY != nowY)
                {
                    newX = nowX; newY = nowY;
                    break;
                }
                else
                {
                    Process p = Program.golobalProcess;
                    var baseAddress = p.MainModule.BaseAddress + 0x00AB97BC;
                    Thread.Sleep(500);
                    int nowHwnd = (int)p.MainWindowHandle;
                    nowX = dm.ReadInt(nowHwnd, $"[[[{baseAddress.ToString("X")}]+0]+8]+10c", 0);
                    nowY = dm.ReadInt(nowHwnd, $"[[[{baseAddress.ToString("X")}]+0]+8]+110", 0);
                }
            }
        }

        /// <summary>
        /// 是否合法的刷怪位置
        /// </summary>
        /// <param name="X">玩家当前坐标X</param>
        /// <param name="Y">玩家当前坐标Y</param>
        /// <param name="mapLH">当前地图大小，用于计算防止BOSS穿图</param>
        /// <returns></returns>
        public static bool IsRightfulPosation(int X, int Y,int mapLH = 0)
        {
            foreach (DisableMap Map in MapList) 
            {
                if (X > Map.Position.LeftX && X < Map.Position.RightX && Y > Map.Position.RightY && Y < Map.Position.LeftY)
                {
                    return false;
                }
            }
            if (mapLH > 0) { }
            return true;
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="A">点位数值</param>
        /// <param name="mapSize">当前地图尺寸</param>
        /// <param name="LimitPx">限制容差</param>
        /// <returns></returns>
        public static int? FindNearestMultipleOfSize(int A,int mapSize,int LimitPx)
        {
            int lowerBound = A - 50;
            int upperBound = A + 50;
            for (int i = lowerBound / 400; i <= upperBound / 400; i++)
            {
                int candidate = i * 400;
                if (candidate >= lowerBound && candidate <= upperBound)
                {
                    return candidate;
                }
                if (candidate > upperBound)
                {
                    break;
                }
            }
            return 0;
        }

        /// <summary>
        /// 获取禁止刷怪地图位置列表
        /// </summary>
        /// <exception cref=""></exception>
        public static void GetDisableMap()
        {
            string filePath = AppContext.BaseDirectory + "Config\\disablemap.json";
            string jsonString = File.ReadAllText(filePath);

            MapList = JsonConvert.DeserializeObject<List<DisableMap>>(jsonString);
        }

        /// <summary>
        /// 按类型随机获取一个NPC信息
        /// </summary>
        /// <param name="Type">0:随机,1:玩家抽奖</param>
        /// <param name="chrLevel">角色等级</param>
        /// <returns></returns>
        public static BossEntityModel GetRandomNpc(int Type,int chrLevel)
        {
            BossEntityModel model = new BossEntityModel();
            List<BossEntityModel> newList = new List<BossEntityModel>();
            if (Type == 0)//英灵
            {
                newList = BossList.FindAll(p => p.Point != "wanjia" && p.RefreshType == "shoudong");
            }
            else {//财神
                if (chrLevel > 0)//指定玩家等级就指定获取，否则按概率论随机
                {
                    newList = BossList.FindAll(p => p.Point == "wanjia" && p.RefreshType == "shoudong" && p.chrLevL <= chrLevel && p.chrLevH >= chrLevel);
                }
                else
                {
                    List<BossEntityModel> caishenList = BossList.FindAll(p => p.Point == "wanjia" && p.RefreshType == "shoudong");
                    foreach (BossEntityModel item in caishenList)
                    {
                        for (int i = 0; i < item.refreshGL; i++)
                        {
                            newList.Add(item);
                        }
                    }
                    newList = ShuffleList(newList);
                }
            }
            //随机返回一个
            if (newList.Count == 1)
            {
                model = newList[0];
            }
            else
            {
                Random Random = new Random();
                int RandomVal = Random.Next(0, newList.Count);
                model = newList[RandomVal];
            }
            return model;
        }
        /// <summary>
        /// 随机打乱列表顺序
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List<T> ShuffleList<T>(List<T> list)
        {
            Random rng = new Random();
            int n = list.Count;
            while (n > 1)
            {
                int k = rng.Next(n);
                T value = list[k];
                list[k] = list[n - 1];
                list[n - 1] = value;
                n--;
            }
            return list;
        }

        /// <summary>
        /// 随机获取一个玩家
        /// </summary>
        /// <param name="LevL">角色最低等级</param>
        /// <param name="LevH">角色最高等级</param>
        /// <returns></returns>
        public static UserInfoModel? GetRandomOnlineUser(int LevL = 0, int LevH = 0)
        {
            string serverAddress = $"{Program.ApiAddress}Api/Interface/GetOneOnlineUser?ServerId={Program.serverModel.Id}&LevL={LevL}&LevH={LevH}";
            string serverInfoStr = CommonFun.HttpGet(serverAddress);
            Thread.Sleep(1000);
            if (serverInfoStr.Contains("获取失败"))
            {
                return null;
            }
            else
            {
                UserInfoModel UserInfo = JsonConvert.DeserializeObject<UserInfoModel>(serverInfoStr.Replace("\\", "").Substring(1, serverInfoStr.Replace("\\", "").Length - 2));
                if (UserInfo != null && UserInfo.UserId > 0)
                {
                    return UserInfo;
                }
            }
            return null;
        }

        /// <summary>
        ///发送公告信息
        /// </summary>
        /// <param name="Content"></param>
        /// <returns></returns>
        public static bool SendOneNotice(string Content)
        {
            string NoticeApiUrl = $"{Program.GmToolDomain}SendNotice";
            string FormData = $"content={Content}";
            string ReturnVal = CommonFun.HttpPostRaw(NoticeApiUrl, FormData);
            if (ReturnVal == "200")
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 上传Boss被杀掉记录
        /// </summary>
        /// <param name="Id">Boss ID</param>
        /// <param name="timeSpan">刷新间隔</param>
        /// <param name="mapName">刷新地图</param>
        /// <returns></returns>
        public static bool SendBossKilledInfo(int Id, int timeSpan, string mapName = "")
        {
            string NoticeApiUrl = $"{Program.ApiAddress}Api/Interface/AddBossKilled";
            DateTimeOffset now = DateTimeOffset.UtcNow;
            long unixTimestamp = now.ToUnixTimeSeconds();
            mapName = string.IsNullOrEmpty(mapName) ? "" : $"{mapName}";
            string FormData = $"Id={Id}&KillTime={unixTimestamp}&ts={timeSpan}&map={mapName}";
            string ReturnVal = CommonFun.HttpPostRaw(NoticeApiUrl, FormData);
            if (ReturnVal.Contains("200"))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 加载地图列表信息
        /// </summary>
        public static void LoadMapInfo()
        {
            string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config\\gamemap.csv");
            if (File.Exists(filePath))
            {
                DataTable MapCsvDt = CommonFun.OpenCSV(filePath, 0, 0, 0, 0, false);
                if (MapCsvDt != null && MapCsvDt.Rows.Count > 0)
                {
                    for (int i = 1; i < MapCsvDt.Rows.Count; i++)
                    {
                        GameMapInfo model = new GameMapInfo();
                        DataRow row = MapCsvDt.Rows[i];
                        model.MapCode = row["COL0"].ToString();
                        model.MapName = row["COL1"].ToString();
                        model.LeftX = Convert.ToInt32(row["COL2"]);
                        model.LeftY = Convert.ToInt32(row["COL3"]);
                        model.BirthX = Convert.ToInt32(row["COL4"]);
                        model.BirthY = Convert.ToInt32(row["COL5"]);
                        model.MapLenth = Convert.ToInt32(row["COL6"]);
                        allMapList.Add(model);
                    }
                }
            }
        }

        /// <summary>
        /// 加载游荡坐标信息
        /// </summary>
        public static void LoadYouDangPointInfo()
        {
            string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config\\youdang.csv");
            if (File.Exists(filePath))
            {
                DataTable BossCsvDt = CsvHelper.OpenCSV(filePath, 0, 0, 0, 0, false);
                if (BossCsvDt != null && BossCsvDt.Rows.Count > 0)
                {
                    for (int i = 0; i < BossCsvDt.Rows.Count; i++)
                    {
                        YouDangBoss model = new YouDangBoss();
                        DataRow row = BossCsvDt.Rows[i];
                        if (!string.IsNullOrEmpty( row["COL0"].ToString()))
                        {
                            model.MapName = row["COL0"].ToString();
                            model.Point = row["COL1"].ToString();
                            YouDangPointList.Add(model);
                        }
                    }
                }
            }
            //YouDangPointList = ShuffleList(YouDangPointList);
        }
    }

    /// <summary>
    /// 游荡英灵刷新位置
    /// </summary>
    public class YouDangBoss {
        public string MapName { get; set; }
        public string Point { get; set; }
    }
}
